package group6renderer.renderernode;

import group6renderer.Display;
import group6renderer.Visitor;

/** ClASS NAME: TableNode
 * DESCRIPTION: A class to deal with the tables
 * COLABORATORING CLASSES: BranchNode, TreeNode, Exception, Display
 * @author jonnie
 */
public class TableNode extends BranchNode
{

	/**
	 * A method to add a child
	 * @param child the TreeNode child to add
	 */
	public void addChild(TreeNode child)throws Exception
    {
	
	if (child instanceof TableRowNode)	
		super.addChild(child);
	else
		{if (child instanceof TextNode)	
			{	parent.addChild(child);	
				TextNode tChild=(TextNode)child;
				if (tChild.checkForLetters(tChild.getText()))
					throw new Exception("Only table rows 'tr' are allowed inside a Table.Action taken:The text is printed after the table data.");
			}
		else
			throw new Exception("Only table rows 'tr' are allowed inside a Table and no other tags.");

		}
	
	}
	
	
    public TableNode(String name)
    {
	this.name=name;
    }

    public void drawNode(Display disp)
    {
	if(goingDown)
	{
	    disp.openTable();
	}
	else
	{
	    disp.closeTable();
	}
	goingDown = !goingDown;
    }

    public boolean hasClosing()
    {
	return true;
    }

    public TreeNode copy()
    {
	return new TableNode(name);
    }
}
